package com.itheima.kafka.controller;

import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
public class HelloController {

    @Autowired
    KafkaTemplate<String,String> kafkaTemplate;

    @GetMapping("/hello")
    public String hello(String msg) {
        kafkaTemplate.send("Topic","Spring-kafka" , msg);
        return "ok";
    }
    @GetMapping("/hello1")
    public String hello1() {
        HashMap<String, String> map = new HashMap<>();
        map.put("name", "小明");
        map.put("age","20");

        String string = JSON.toJSONString(map);
        kafkaTemplate.send("map","Spring-kafka" ,string);
        return "ok";
    }
}